<?php
class wms_receipt_dlyitemsstoragelife{

    /**
     *
     * 发货单明细对应的批次明细生成方法
     * @param array $sdf 批次信息
     */
    public function generate($sdf,&$msg){
        //校验传入参数
        if(!$this->checkParams($sdf,$msg)){
            return false;
        }

        $dlyItemsSLObj = app::get('wms')->model('delivery_items_storage_life');

        //事务开启
        $dlyItemsSLObj->db->exec('begin');

        //循环每行批次明细进行保存
        foreach($sdf['items'] as $item){
            foreach($item['expire_bns_info'] as $expire_bn_info){
                $data = array();

                $data['item_id']  = $item['item_id'];
                $data['bm_id']  = $item['bm_id'];
                $data['delivery_id']  = $sdf['bill_id'];
                $data['expire_bn']  = $expire_bn_info['expire_bn'];
                $data['number']  = $expire_bn_info['nums'];

                if(!$dlyItemsSLObj->save($data)){
                    $dlyItemsSLObj->db->rollBack();
                    return false;
                }
                unset($data);
            }
        }

        $dlyItemsSLObj->db->commit();
        return true;
    }

    private function checkParams($params,&$msg){
        return true;
    }
}